Keep meta data around task, even after disabled.#352
Open
vbabiy wants to merge 1 commit intocelery:mainfrom
Open
Keep meta data around task, even after disabled.#352vbabiy wants to merge 1 commit intocelery:mainfrom
vbabiy wants to merge 1 commit intocelery:mainfrom
Conversation
auvipy
requested changes
Jun 14, 2020
| self.routing_key = self.routing_key or None | ||
| self.queue = self.queue or None | ||
| self.headers = self.headers or None | ||
| if not self.enabled: |
Member
There was a problem hiding this comment.
does this create any regreassion?
| if self.model.one_off and self.model.enabled \ | ||
| and self.model.total_run_count > 0: | ||
| self.model.enabled = False | ||
| self.model.total_run_count = 0 # Reset |
auvipy
requested changes
Mar 30, 2025
Member
auvipy
left a comment
There was a problem hiding this comment.
please come with an up to date solution
There was a problem hiding this comment.
Pull Request Overview
This PR ensures that task metadata (last_run_at and total_run_count) is preserved when disabling tasks and exposes the run count in the Django admin.
- Stop clearing
total_run_countfor one-off tasks when they disable. - Prevent
last_run_atfrom being reset on save if a task is disabled. - Add
total_run_countas a readonly field in the admin UI.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| django_celery_beat/schedulers.py | Removed the reset of total_run_count when disabling a task |
| django_celery_beat/models.py | Deleted logic that cleared last_run_at on save for disabled tasks |
| django_celery_beat/admin.py | Added total_run_count to admin form fields and readonly view |
Comments suppressed due to low confidence (2)
django_celery_beat/schedulers.py:128
- [nitpick] Consider adding a comment here explaining why
total_run_countreset was removed, to clarify the intended behavior for future maintainers.
self.model.no_changes = False # Mark the model entry as changed
django_celery_beat/models.py:577
- Add a unit test to verify that
last_run_atis preserved when a task is disabled, ensuring this change isn't accidentally reverted.
self._clean_expires()
| ('Schedule', { | ||
| 'fields': ('interval', 'crontab', 'solar', 'clocked', | ||
| 'start_time', 'last_run_at', 'one_off'), | ||
| 'start_time', 'last_run_at','total_run_count', 'one_off'), |
There was a problem hiding this comment.
[nitpick] Insert a space after the comma between 'last_run_at' and 'total_run_count' for consistent formatting.
Suggested change
| 'start_time', 'last_run_at','total_run_count', 'one_off'), | |
| 'start_time', 'last_run_at', 'total_run_count', 'one_off'), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
total_run_countto the admin